Get Chat Labels
Get all labels assigned to a specific chat.
Authentication Required
Login to swap the placeholders with your real Instance ID and Access Token.
Log InNo query parameters required
This endpoint doesn't expect data in the URL.
Best practices
Use this to build 'Smart Views' in your custom CRM.
Fetch only the necessary fields to optimize performance.
Reading the Thread Metadata: Fetch All Labels for a Chat
Individual conversations often wear many hats. A single chat with a customer might simultaneously be a "VIP," have a "Pending Payment," and be "Assigned to Alice." The Get Chat Labels endpoint allows you to retrieve the full array of labels currently attached to a specific chat identifier.
🏗️ Core Concept
This endpoint is the primary tool for Conversational Discovery. It answers the question: "What is the current business context of this specific thread?"
Key Capabilities:
- UI Hydration: Populate the "tags" or "labels" section of your custom agent dashboard when a chat is selected.
- Conditional Logic: Trigger different bot responses or agent alerts based on the chat's existing labels.
- State Audit: Verify if a chat has correctly transitioned through your workflow stages (e.g., ensuring "Lead" was removed before "Customer" was added).
🚀 Priority Use Cases
1. Smart Auto-Replies
Adjust your bot's tone or logic based on the user's current categories.
const labels = await api.getLabelsForChat('123456789@c.us');
const isVIP = labels.some(l => l.name === 'VIP');
if (isVIP) {
await api.sendText(chatId, "Hello VIP! We've prioritized your request for immediate agent review.");
} else {
await api.sendText(chatId, "Thanks for your message. We'll get back to you soon!");
}
2. CRM "State Refresh"
When an agent opens a contact in your CRM, fetch the latest WhatsApp labels to ensure the external CRM state matches the reality of the WhatsApp thread.
3. Preventing Duplicate Tags
Before adding a label, check if it's already present to avoid redundant API calls (though the add-label operation is idempotent).
🔄 State Consistency & Synchronization
In a multi-agent environment, ensuring that every agent sees the same labels at the same time is critical for preventing duplicated work.
The "Stale Data" Challenge
If Agent A adds a "Processing" label while Agent B is looking at the same chat, Agent B's dashboard may still show "Unassigned."
- The Check-Before-Action Rule: Before an agent clicks "Send Invoice," your backend should call this endpoint to verify the chat hasn't already been tagged with "Invoice Sent" by another automated process or agent.
- Websocket Pushing: Listen to
label.chat.addedandlabel.chat.removedwebhooks. When they arrive, use this endpoint to fetch the full current state and push it via Websockets to all active agent browsers.
🛡️ Audit Logging & Compliance
Labels are often used to trigger significant business events (e.g., tagging a chat "Refund Approved" to trigger a payment gateway).
Building an Audit Trail
WhatsApp does not natively store a history of who applied a label and when. We recommend:
- Intercepting API Calls: Every time your system calls
PUT /v2/labels/{id}/chats/{chatId}, log the user ID of the agent who initiated it. - Snapshotting States: Periodically use this Get Chat Labels endpoint to take a snapshot of high-value chats to track their journey through your funnel.
🛠️ Integration Patterns: Visual Feedback Systems
The "Label Badge" Hydration
- Fetch List: Call this endpoint for the active chat.
- Map Styles: Cross-reference the
colorindex with your local CSS theme. - Render: Display a horizontal list of badges in your sidebar.
async function renderChatMetadata(chatId) {
const currentLabels = await api.getLabelsForChat(chatId);
return currentLabels.map(label => ({
text: label.name,
bgcolor: label.colorHex,
isUrgent: label.color === 0 // Red index
}));
}
⚠️ Important Behaviors & Edge Cases
- Multi-Label Support: WhatsApp supports multiple labels per chat. This endpoint always returns an array, which may be empty if no labels are applied.
- Id/Name/Color Trio: Each label in the response includes its unique ID, name, current color index, and hex code.
- Performance: This is a lightweight call. However, if building a high-volume dashboard, consider caching the results until a webhook is received.
🤖 Advanced Integration: Bot Interaction Patterns
When building an automated assistant, the labels attached to a chat act as a "Contextual Memory."
The "Label-Aware" Bot
Your bot can query this endpoint at the start of a session to determine the user's tier or status.
- Incoming Message: User says "Price check."
- Lookup: Bot calls this endpoint.
- Branching logic:
- If label "Wholesale" (ID 5) exists → Give bulk pricing.
- If label "Retail" (ID 2) exists → Give standard pricing.
- If no labels exist → Ask the user for their customer type.
async function getBotResponse(chatId, message) {
const meta = await api.getLabelsForChat(chatId);
const isWholesale = meta.some(l => l.id === '5');
if (message.includes('price')) {
return isWholesale ? getBulkPriceList() : getStandardPriceList();
}
}
🎯 Best Practices
- Don't Over-Poll: Use Webhooks to keep your local database in sync instead of calling this every time a message is received.
- Handle Empty States: Gracefully render your UI when the response is an empty array
[]. - Cross-Reference with Global Directory: Use the results here alongside the
Get All Labelslist to provide a full "Label Picker" experience for agents.
Request Parameters
Configure the parameters required to interact with this endpoint. All query and body arguments are listed below with their details.
URL Parameters
Passed in the URL query stringstring | Your unique WhatsApp Instance ID Example: | ||
string | Your API Access Token Example: | ||
string | The unique ID of the chat (e.g., 123456789@c.us) Example: |
Request Samples
Use these ready-to-go code snippets to integrate our API into your project quickly and efficiently. Choose your preferred language and library.
Expected Responses
Explore all possible responses and outcomes from the server. We have documented each status code with data examples to make success and error handling easier.
Example
{
"0": {
"id": "1",
"name": "New Customer",
"color": 0,
"colorHex": "#ff9485"
}
}Command Palette
Search for a command to run...